/*
* @Description:网络管理
* @Author: lil
* @Date: 2021/12/22
**/
<template>
  <div class="app-container">
    <el-tabs v-model="activeName" :before-leave="beforeLeave" @tab-click="handleClick">
      <el-tab-pane :disabled="disabledFirst" label="网络扩展" name="0">
        <network-extend-index :key="timer" @extendState="extendState"></network-extend-index>
      </el-tab-pane>
      <el-tab-pane label="网络部署" name="1">
        <network-deploy :key="timer" @getInfo="getDeployInfo"></network-deploy>
      </el-tab-pane>
      <el-tab-pane :disabled="disabledThird" label="网络清理" name="2">
        <network-clean :key="timer"></network-clean>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
  import {
    loadStatus,
    alertStatus
  } from "@/api/blockchain/deployhost";
  import networkExtendIndex from "./networkExtend/networkExtendIndex";
  import networkDeploy from "./networkDeploy";
  import networkClean from "./networkClean";
  export default {
    components: {
      networkExtendIndex,
      networkDeploy,
      networkClean,
    },
    data() {
      return {
        activeName: "1",
        disabledFirst: true,
        disabledThird: true,
        timer: "",
        configState: false
      };
    },
    mounted() {
      this.initDeployData();
    },
    methods: {
      initDeployData() {
        loadStatus().then((res) => {
          this.disabledFirst = !Boolean(res.data.network_extend);
          this.disabledThird = !Boolean(res.data.network_clean);
        });
      },
      getDeployInfo(val) {
        this.disabledFirst = !val;
        this.disabledThird = val;
        alertStatus(0, 2, 2, 2, !val * 1, val * 1);
      },
      beforeLeave() {
        if (this.configState) {
          this.$message.warning('网络扩展中，请稍后点击！');
          return false
        }
      },
      handleClick() {
        if (this.configState) {
          this.$message.warning('网络扩展中，请稍后点击！');
          return
        }
        this.timer = new Date().getTime();
      },
      extendState(val) {
        this.configState = val;
      }
    },
  };

</script>
